package com.booklove.controller.school;

import com.booklove.domain.dto.PageDTO;
import com.booklove.domain.po.Apply;
import com.booklove.domain.query.ApplyQuery;
import com.booklove.service.school.ApplyService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;



@Slf4j
@RestController("applyCLL")
@RequestMapping("/applys")
@RequiredArgsConstructor// 使用基本注解的注入形式，仅仅注入需要的变量
public class ApplyController {

    private final ApplyService applyService;

    /**
     * 保存新增
     */
    @PostMapping("/")
    void saveApply(@RequestBody Apply applyFormDTO) {
        Apply apply = new Apply();
        BeanUtils.copyProperties(applyFormDTO, apply);
        applyService.saveApply(apply);
    }


    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/id")
    void deleteApply(@RequestParam("id") Long id) {
        applyService.deleteById(id);
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    Apply getApply(@PathVariable Long id) {
        return applyService.getById(id);
    }


    /**
     * 编辑数据
     *
     * @param applyFormDTO 实体
     * @return 编辑结果
     */
    @PutMapping("/")
    void updateApply(@RequestBody Apply applyFormDTO) {
        applyService.updateById(applyFormDTO);
    }


    /**
     * 分页查询
     *
     * @param applyQuery 筛选条件
     * @return 查询结果
     */
    @GetMapping("/page")
    PageDTO<Apply> applysPageQuery(ApplyQuery applyQuery) {
        return applyService.queryApplysPage(applyQuery);
    }

}

